package com.project.personal_blog.garbage_classification_management_system.mapper;

import com.project.personal_blog.garbage_classification_management_system.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface rootMapper {
    // 删除所有用户
    @Delete("delete from user")
    boolean deleteUsers();

    // 查询所有用户
    @Select("select * from user")
    List<User> selectUsers();

    // 根据用户名查询用户
    @Select("select id, name, email, phonenumber,update_time,gt_id from user where name = #{username}")
    User selectUserByUsername(String username);

    // 根据用户ID查询用户
    @Select("select id, name, email, phonenumber,update_time,gt_id from user where name = #{id}")
    User selectUserById(int id);

    // 根据电话号码查询用户
    @Select("select id, name, email, phonenumber,update_time,gt_id from user where name = #{phonNumber}")
    User selectUserByPhoneNumber(String phoneNumber);

    // 根据邮箱查询用户
    @Select("select id, name, email, phonenumber,update_time,gt_id from user where name = #{email}")
    User selectUserByEmail(String email);

    // 添加用户
    @Insert("insert into user  values (id, name, email, password, phonenumber, gt_id, update_time)")
    User addUser(User user);

    // 删除用户
    @Delete("delete from user where id = #{id}")
    boolean deleteUser(int id);

    // 更新用户
    @Update("update user set name=#{name},email=#{emai},phonenumber=#{phonenumber},gt_id=#{},password=#{password},update_time=#{updatetime} where id = #{}")
    User updateUser(User user);

    // 分页查询用户
    @Select("SELECT * FROM user ORDER BY id LIMIT #{offset}, #{limit}")
    boolean PageUser(Integer pageNumber, Integer pageSize);

    // 根据id升序和id降序排序用户
    @Select("SELECT * FROM user WHERE id BETWEEN #{id1} AND #{id2} ORDER BY id")
    boolean sortUserById(Integer id1, Integer id2);

    // 根据name升序和name降序排序用户
    @Select("SELECT * FROM user WHERE name BETWEEN #{name1} AND #{name2} ORDER BY name")
    boolean sortUserByName(String name1, String name2);

    // 根据phoneNumber升序和phoneNumber降序排序用户
    @Select("SELECT * FROM user WHERE phonenumber BETWEEN #{phoneNumber1} AND #{phoneNumber2} ORDER BY phonenumber")
    boolean sortUserByPhoneNumber(String phoneNumber1, String phoneNumber2);

    // 根据email升序和email降序排序用户
    @Select("SELECT * FROM user WHERE email BETWEEN #{email1} AND #{email2} ORDER BY email")
    boolean sortUserByEmail(String email1, String email2);
}
